/**
 * Kellen Donohue
 * May 20, 2011
 * RailsModelParserTestCase.java
 */
package edu.washington.cs.labspecimentransport.test;

import java.io.File;
import java.util.Scanner;

import junit.framework.TestCase;
import edu.washington.cs.labspecimentransport.data.RailsModelParser;

/**
 * @author Kellen
 * 
 */
public class RailsModelParserTestCase extends TestCase {
	public void testRailsModelParser() {

		String inputFile = "test_schema.rb";
		// TODO: Make it file.separatorChar
		String outputDir = "dataobjects/";

		String[] args = { inputFile, outputDir };

		try {
			RailsModelParser.main(args);
		} catch (Exception e) {
			fail("Couldn't run the parser");
		}

		// Make sure the new file was created
		File output = new File(outputDir + "CheckIn.java");
		File goal = new File(outputDir + "CheckIn.goal");
		assertNotNull(output);
		// Now make sure they are the same
		try {
			Scanner outputScanner = new Scanner(output);
			Scanner goalScanner = new Scanner(goal);
			while(outputScanner.hasNext()) {
				String next = outputScanner.nextLine();
				// Ignore comment lines - the timestamp will break the test otherwise
				if(next.startsWith(" *")) {
					goalScanner.nextLine();
					continue;
				}
				assertEquals(next, goalScanner.nextLine());
			}
		} catch (Exception e) {
			fail("Couldn't create scanners");
		}
		// Good job, didn't crash
		assertTrue(true);
	}
}
